#include <iostream>
#include <fstream>
#include <sstream>


// turn char* to float
float slove(char* str){
    float x = atof(str);
    return x;
}

int main(){

    float *datas = new float[200*4];
    float *lables = new float[200];

    int count = 0;
    
    std::ifstream file("dealdata.txt");
    if(file.is_open()){
        char buf[100];
        while(file.getline(buf, sizeof(buf))){
            int s = 0;
            int idx = 0;
            char str[5][10];
            for(int i = 0; i < sizeof(buf); i++){
                if (buf[i] == '\n'){
                    break;
                }

                if (buf[i] == ','){
                    str[s][idx] = '\0';
                    s++;
                    idx = 0;
                }else{
                    str[s][idx++] = buf[i];
                }
            }

            for (int i = 0; i < 5; i++){
                if(i < 4){
                    datas[i + count*4] = slove(str[i]);
                }else{
                    lables[count] = slove(str[i]);
                }
            }
            count++;
        }
        
    }else{
        std::cout << "Unable to open file" << std::endl;
    }


    file.close();

    // for(int i = 0; i < 5; i++){
    //     std::cout << nums[i] << std::endl;
    // }
    // shape (b, 4)
    std::cout << "datas: "  << std::endl;

    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 4; j++){
            std::cout << datas[i*4 + j] << " ";
        }
        std::cout << std::endl;
    }

    std::cout << "lables: "  << std::endl;

    for(int i = 0; i < 5; i++){
        std::cout << lables[i] << " ";
    }
    std::cout << std::endl;

    delete[] datas;
    delete[] lables;

    return 0;
}